

var jsremote = {
  _socket:null,
  _url:null,
  connect:function(url){
    this._url = url;
    this._socket = io.connect(this._url);
  },
  get:function(id, receive){
    var socket = this._socket;
    
    socket.emit('jsr.get', id);
    socket.on('jsr.get.' + id, function(obj){
      obj.setProperty = function(name, value){
        if(obj[name] != value){
          obj[name] = value;
          socket.emit('jsr.change.' + id, {
            name:name,
            value:value
          });
        }
      };
      
      obj.notifyChange = function(){
        socket.emit('jsr.notify.' + id);
      };
     
      socket.on('jsr.onchange.' + id, function(rep){
        var name = rep.name;
        var value = rep.value;
        obj[name] = value;
        obj.changeListener();
      });
      
      socket.on('jsr.onnotify.' + id, function(){
        obj.changeListener();
      });
      
      receive(obj);
    });
  }
};